﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using UniversalDataAccess.BusinessEntities;
using UniversalDataAccess;
using System.Configuration;

namespace WebApplication1
{
    /// <summary>
    /// Summary description for DivisionsLogicService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class DivisionsLogicService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        #region Select / Insert / Update /Delete Division.

        [WebMethod]
        public Division SelectDivision_By_DataBase_And_Id(string databaseName, int id)
        {
            try
            {
                DivisionsDataAccess dataAccess = null;


                dataAccess = new DivisionsDataAccess(databaseName, ConfigurationManager.ConnectionStrings[databaseName].ConnectionString, false);
                return dataAccess.SelectDivisionBy_Id(id);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public List<Division> SelectDivisionListByDataBaseName(string dataBaseName)
        {
            try
            {
                DivisionsDataAccess e = new DivisionsDataAccess(dataBaseName, ConfigurationManager.ConnectionStrings[dataBaseName].ConnectionString, false);

                return e.SelectDivisionsList();
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public void InsertDivision( Division division)
        {
            try
            {
                DivisionsDataAccess e = new DivisionsDataAccess(division.DataBaseName,
                    ConfigurationManager.ConnectionStrings[division.DataBaseName].ConnectionString, false);

                int new_Id = -1;
                e.InsertDivision(division, ref new_Id);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public void UpdateDivision( Division division)
        {
            try
            {
                DivisionsDataAccess e = new DivisionsDataAccess(division.DataBaseName,
                    ConfigurationManager.ConnectionStrings[division.DataBaseName].ConnectionString, false);

                e.UpdateDivision(division);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [WebMethod]
        public void DeleteDivision( Division division)
        {
            try
            {
                DivisionsDataAccess e = new DivisionsDataAccess(division.DataBaseName,
                    ConfigurationManager.ConnectionStrings[division.DataBaseName].ConnectionString, false);

                e.DeleteDivision(division);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        #endregion              

    }
}
